
#include "Directory.h"
        
        char* Directory::GetCurrent(){
            char cwd[256];
            char* dir = getcwd(cwd, sizeof(cwd));
            if(dir==NULL)
                return "";
            return dir;
        }

        void Directory::Create(std::string & dir)
        {
            if (!Existe(dir))
                mkdir(dir.c_str(), S_IRWXU);
        }

 	void Directory::Remover(std::string & dir)
 	{
		  struct dirent *next_file;
		  DIR *dirctory;

		  char filepath[256];

		  dirctory = opendir(dir.c_str());
		  next_file = readdir(dirctory);
		  while ( next_file != NULL  )
		  {
			  sprintf(filepath, "%s/%s", dir.c_str(), next_file->d_name);
			  remove(filepath);
			  next_file = readdir(dirctory);
		  }
		  closedir(dirctory);
	}
         
        bool Directory::Existe(std::string & dir)
	{
		DIR *pDir;
		bool existe = false;

		pDir = opendir (dir.c_str());
                
		if (pDir != NULL)
		{
			existe = true;
			(void) closedir (pDir);
		}
		return existe;
	}
        
        void  Directory::GetListPath (std::string & dir, std::vector<std::string> & files, std::string extension)
	{
		DIR* dp = opendir(dir.c_str());
		struct dirent* dirp;
		std::string filename = "";

		while ((dirp = readdir(dp)) != NULL) {
			filename = std::string(dirp->d_name);
			if ( extension.size() > 0 )
			{
				if(filename.find_last_of(".") != std::string::npos)
				{
					if( filename.substr(filename.find_last_of(".") ) == extension ){
						files.push_back(dir+'/'+filename);
					}
				}
			}
			else {
				files.push_back(dir+'/'+filename);
			}
		}
		closedir(dp);
                std::sort(files.begin(), files.end());
	}/* Dado un directorio, crea un vector con los nombres de los archivos. */